package com.v.etl;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class WebLogMapper extends Mapper<LongWritable, Text, Text, NullWritable> {


    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, NullWritable>.Context context) throws IOException, InterruptedException {

        String string = value.toString();


        boolean result = parseLog(string,context);


        if(!result){
            return;
        }

        context.write(value,NullWritable.get());


    }

    private boolean parseLog(String string, Mapper<LongWritable, Text, Text, NullWritable>.Context context) {

        String[] fields = string.split(" ");

        if(fields.length > 11){
            return true;
        } else {
            return false;
        }


    }
}
